package com.zhanggm.springcloud.jpa.repository;

import com.zhanggm.springcloud.jpa.entity.TbDocSkill;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
@author Zhanggm
*/
public interface TbDocSkillRepository extends JpaRepository<TbDocSkill, Integer> {
    /**
     * 根据医生Id，查询关系列表
     * @param docId
     * @return
     */
    List<TbDocSkill> findByDocId(Integer docId);

    /**
     * 根据医生Id，查询技能Id列表
     * @param docId
     * @return
     */
    @Query(value = "select skill_id from tb_doc_skill where doc_id=:docId",nativeQuery = true)
    List<Integer> findSkillIdListByDocId(@Param("docId") Integer docId);

    /**
     * 根据技能Id查询关系列表
     * @param skillId
     * @return
     */
    List<TbDocSkill> findBySkillId(Integer skillId);

    /**
     * 根据医生Id,删除数据
     * @param docId
     * @return
     */
    @Transactional
    @Modifying
    int deleteByDocId(Integer docId);

}
